package com.ruoyi.system.apiController;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.YyAppointment;
import com.ruoyi.system.domain.YyAppointmentTime;
import com.ruoyi.system.service.IYyAppointmentService;
import com.ruoyi.system.service.IYyAppointmentTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

//预约接口

@RestController
@RequestMapping("/api/appointment")
public class YyAppointmentApiController {

    @Autowired
    private IYyAppointmentService yyAppointmentService;
    @Autowired
    private IYyAppointmentTimeService yyAppointmentTimeService;

    /**
     * 查询今天哪个时间端还能预约
     */
    @GetMapping("/appointmentTime")
    public AjaxResult appointmentTime(Integer doctorId, Integer departmentId) {
        List<Map<String, Object>> list =  yyAppointmentTimeService.selectAppointmentTime(doctorId,departmentId);
        return AjaxResult.success(list);
    }


    /**
     * 患者预约
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody YyAppointment yyAppointment) {
        int i = yyAppointmentService.insertYyAppointment2(yyAppointment);
        if (i < 1){
            return AjaxResult.error("预约失败");
        }
        return AjaxResult.success("预约成功");
    }


    /**
     * 查看所有预约
     */
    @GetMapping("/list")
    public AjaxResult list(YyAppointment yyAppointment) {
        List<YyAppointment> list = yyAppointmentService.selectAllYyAppointmentList(yyAppointment);
        return AjaxResult.success(list);
    }

    /**
     * 预约审核
     */
    @PostMapping("/check")
    public AjaxResult check(@RequestBody YyAppointment yyAppointment) {
        int i = yyAppointmentService.updateYyAppointment(yyAppointment);
        if (i < 1){
            return AjaxResult.error("修改失败");
        }
        return AjaxResult.success("修改成功");
    }
}
